import json
import requests

url = "http://127.0.0.1:18332"
auth = ("username", "password")


def omnicore_rpc(method, params):
    payload = json.dumps({"method": method, "params": params})
    response = requests.request("POST", url, data=payload, auth=auth)
    print(response.text)
    return response.text


def get_latest_block_hash():
    return omnicore_rpc(omnicore_rpc(method='omni_getlatestblock', params=[]))


def get_block():
    return omnicore_rpc(omnicore_rpc(method='omni_getblock', params=[]))


def rpc_getInfo():
    return omnicore_rpc('omni_getinfo', [])


def rpc_gettransaction(txid):
    return omnicore_rpc('omni_gettransaction', [txid])


# print(rpc_getInfo())
# print(rpc_gettransaction('1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d'))
